package request

import (
	"github.com/astaxie/beego/validation"
	"shop-bean/dto"
	"shop-common/utils/pagehelper"
	"shop-common/utils/regular"
)

type SystemStoreRequest struct {
	Id           uint   `json:"id"`           //id
	Name         string `json:"name"`         //门店名称
	Introduction string `json:"introduction"` //简介
	Phone        string `json:"phone"`        //手机号码
	//Address         string             `json:"address"`                       //省市区
	DetailedAddress string             `json:"detailedAddress"`               //详细地址
	DayTime         []string           `json:"dayTime"`                       //每日营业开关时间
	Image           *dto.AttachmentDTO `json:"image"`                         //门店logo
	OblongImage     *dto.AttachmentDTO `json:"oblongImage"`                   //门店推荐图
	Longitude       string             `json:"longitude"`                     //经度
	Latitude        string             `json:"latitude"`                      //纬度
	Area            string             `json:"area" binding:"required"`       //区 必填
	AreaId          uint               `json:"areaId" binding:"required"`     //区id 必填
	City            string             `json:"city" binding:"required"`       //市 必填
	CityId          uint               `json:"cityId" binding:"required"`     //市id 必填
	Province        string             `json:"province" binding:"required"`   //省份 必填
	ProvinceId      uint               `json:"provinceId" binding:"required"` //省份id 必填

	Status uint8 `gorm:"type:tinyint;not null;default:2" json:"status"` //状态  1:隐藏   2:显示   3:回收站
	//ValidTime string `json:"validTime"` //核销有效日期
}

func (s *SystemStoreRequest) Valid(v *validation.Validation) {
	if s.Name == "" {
		v.SetError("Name", "请填写门店名称")
	} else if len(s.Name) > 100 {
		v.SetError("Name", "门店名称不能超过100个字符")
	} else if !regular.IsMobile(s.Phone) {
		v.SetError("Phone", "手机号格式不符合规范")
	} else if s.DetailedAddress == "" {
		v.SetError("DetailedAddress", "请填写详细地址")
	} else if len(s.DetailedAddress) > 255 {
		v.SetError("DetailedAddress", "详细地址不能超过255个字符")
	} else if s.Longitude == "" {
		v.SetError("Longitude", "请选择经度")
	} else if s.Latitude == "" {
		v.SetError("Latitude", "请选择经纬度")
	} else if s.Image == nil || s.Image.AttId == 0 {
		v.SetError("ImageAttachment", "请上传门店logo")
	} else if s.OblongImage == nil || s.OblongImage.AttId == 0 {
		v.SetError("OblongAttachment", "请上传门店推荐图")
	} else if !(len(s.DayTime) == 2 && s.DayTime[0] != "" || s.DayTime[1] == "") {
		v.SetError("DayTime", "每日营业开关时间不合法")
	}

	//else if s.Address == "" {
	//	v.SetError("Address", "提货点地址")
	//} else if len(s.Address) > 255 {
	//	v.SetError("Address", "提货点地址不能超过255个字符")
	//}
}

type UpdateSystemStoreRequest struct {
	Id     uint  `json:"id" binding:"required"`                 //id
	Status uint8 `json:"status" binding:"required" default:"2"` //状态  1:停用  2:启用  3:回收站
}

type SystemStorePageRequest struct {
	pagehelper.SearchPageRequest
	//Type uint8 `json:"type" form:"type"` //1: 显示 2: 隐藏 3: 软删除
}
